<?php

/*

  Action	$5

  +1 Card; +1 Action.
  Reveal your hand. Reveal cards from your deck until you reveal a card that isn’t a duplicate of one in your hand.
  Put it into your hand and discard the rest.

 */

class HuntingParty extends Card implements iAction, iKingdom, iCornucopia {

    public function __construct() {
        parent::__construct("Hunting Party", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "Reveal your hand. Reveal cards from your deck until you reveal a card that isn’t a duplicate of one in your hand.  Put it into your hand and discard the rest.");
    }
    
    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
         ScreenDisplay::addScreenMessage($game, true, "get +1 action  and draw " . nicePrint($drawed_cards), "get +1 action and draws " . sizeof($drawed_cards) . " cards");


        $playHand = $game->getPlayHand();
         ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($playHand), "reveals " . ScreenDisplay::$LMSG);

        $unique = getUniqueCards($playHand);

        $temp = array();
        foreach ($unique as $unique_card) {
            $temp[$unique_card->getKey()] = $unique_card;
        }
        $unique = $temp;
        //only looking on the top card
        $card = $game->peekCardFromDrawDeck();
        $discardCards = array();
        $good_card = null;
        
        while ($card != null) {
            if (!array_key_exists($card->getKey(), $unique)) {
                $good_card = $game->drawCards(1);
                break;
            } else {
                $card = $game->removeCardFromDrawDeck();
                $discardCards[] = $card;
            }
            $card = $game->peekCardFromDrawDeck();
        }
        
         ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($discardCards) . " and put " . nicePrint($good_card) . " in your hand", 
                "reveals " . nicePrint($discardCards) . " and puts " . nicePrint($good_card) . " in his hand");
        
        $game->discardTempDiscardCards($discardCards);
        $game->cardActionFinished();
        return true;
    }

}

?>